<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 清空数组
      (function () {
        let arr = [1, 2, 3];
        let arr2 = arr;
        // arr=[]//此方法清空将不会清空arr2的
        // arr.length=0 //此方法清空会将arr2也一同清空
        // arr.splice(0,arr.length)//都会清空
        while (arr.pop()) {} //都会清空
        console.log(arr, arr2);
      })();
    </script>
  </body>
</html>
